import { http } from "@/utils/http";
import { type sortingOrderItemType } from "./types";

// 获取待分拣包裹数量

export const getSortingPendingNumApi = (warehouseId: string) => {
  // console.log("getLogin data:", data);
  return http.request<any>("get", `/cp/orderfills/pending/count`, {
    params: {
      warehouseId: warehouseId
    }
  });
};
// type 查询类型 1=拣货单 2=分拣单
type sortingListQueryType = {
  warehouseId: string;
  queryDate: string;
  skip: number;
  limit: number;
  type: number;
};
type sortingListResType = {
  total: number;
  list: sortingOrderItemType[];
};
// 获取拣货分拣单列表
export const getSortingListApi = (queryObj: sortingListQueryType) => {
  // console.log("getLogin data:", data);
  return http.request<sortingListResType>("get", `/cp/orderfill-sortings`, {
    params: {
      ...queryObj
    }
  });
};

// 创建

export const postSortingOrderApi = (data: any) => {
  return http.request<any>("post", `/cp/orderfill-sortings`, {
    params: {
      ...data
    }
  });
};

// 根据单号查明细
export const getSortingOrderDetailApi = (sortingNo: string) => {
  return http.request<any>("get", `/cp/orderfill-sortings/${sortingNo}`);
};

// 根据包裹id查询药品明细

export const getPackageDrugsApi = orderfillId => {
  return http.request<any>("get", `/cp/orderfills/${orderfillId}/drugs`);
};

export const printSortingOrderApi = sortingId => {
  return http.request<any>("post", `/cp/orderfill-sortings/${sortingId}/print`);
};

export const printPackgeApi = orderfillIds => {
  return http.request<any>("post", `/cp/orderfills/print`, {
    params: { orderfillIds: orderfillIds.join(",") }
  });
};

// 根据69码查询药品
export const getDrugsBy69Api = (warehouseId, no) => {
  return http.request<any>("get", `/cp/drugs/europea-article-number/${no}`, {
    params: {
      warehouseId
    }
  });
};

// 拣货完成
export const submitSortingApi = (sortingId, userId) => {
  return http.request<any>(
    "post",
    `/cp/orderfill-sortings/${sortingId}/complete?userId=` + userId
  );
};
// 挂起包裹

export const hangupPackageApi = (orderfillId, userId) => {
  return http.request<any>(
    "post",
    `/cp/orderfills/${orderfillId}/hold?userId=` + userId
  );
};
// 解除包裹单挂起
export const deleteHangupPackageApi = (orderfillId, userId) => {
  return http.request<any>(
    "post",
    `/cp/orderfills/${orderfillId}/unhanging?userId=` + userId
  );
};

// 汇总

export const getSortingSummaryDetailApi = sortingId => {
  return http.request<any>(
    "get",
    `/cp/orderfill-sortings/${sortingId}/summary`
  );
};

// 汇总单完成
export const postSortingSummaryApi = (sortingId, userId) => {
  return http.request<any>(
    "post",
    `/cp/orderfill-sortings/${sortingId}/complete-picking?userId=${userId}`
  );
};
